<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body { margin: 0; }
    </style>
</head>
<body>
    <div id="d" data-id="123"></div>



    <script src="./three.js"></script>
    <script src="./node_modules/three/examples/js/controls/OrbitControls.js"></script>
    <script src="./node_modules/three/examples/js/controls/DragControls.js"></script>
    <script>
        const scene = new THREE.Scene();
        const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );

        const renderer = new THREE.WebGLRenderer();
        renderer.setSize( window.innerWidth, window.innerHeight );
        document.body.appendChild( renderer.domElement );

        const geometry = new THREE.DodecahedronGeometry(100,0);
        const material = new THREE.MeshLambertMaterial({color:0x049ef4});
        const cube = new THREE.Mesh( geometry, material );
        scene.add( cube );
        cube.rotation.x=0.5
        cube.rotation.y=0.5

        camera.position.z = 500;

        var controls = new THREE.OrbitControls(camera,renderer.domElement);//创建控件对象
        controls.addEventListener('change', animate);//监听鼠标、键盘事件

        const DrageControls = new THREE.DragControls( [cube], camera, renderer.domElement );
        DrageControls.addEventListener('drag', function(ev){
            console.log(ev)
            animate()
        });//监听鼠标、键盘事件


        const light = new THREE.AmbientLight( 0Xffffff ); // soft white light
        scene.add( light );

        const pointlight = new THREE.PointLight( 0xdef0f4, 10, 500 );
        pointlight.position.set( 200, 300, -100 );
        scene.add( pointlight );

        function animate() {
            // requestAnimationFrame( animate );
            // cube.rotation.x += 0.01;
            // cube.rotation.y += 0.01;
            renderer.render( scene, camera );
        }
        animate();
    </script>
</body>
</html>